<!--
* description: 供应商信息管理新增/修改弹窗
* author: liuzf
* createdDate: 2019-11-4
-->
<template>
  <section class="editWholeRoleManage">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="500px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :role-org-type="comp.roleOrgType"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :options="comp.options"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            :dataToObject="comp.dataToObject"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
      <!-- <div v-if="!this.isAdd()" class="promptSpan">
        <span>提示：供应商状态一旦改为否则不能逆转操作</span>
      </div>-->
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import { basedataApi } from "@/api/wms/basedata";
export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader") // 弹窗标题
  },
  // 组件混入对象
  mixins: [formMixins],
  props: {
    isShowChooes: { type: Boolean, default: true }
  },

  data() {
    const viewPageCode = "supplierMessage-edit";
    return {
      // 保存API配置对象
      apiConfig: basedataApi.warehousesave,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save") /* 保存*/,
          icon: "iconfont  icon-preservation",
          position: "right"
        },
        {
          compKey: "btnKey2",
          type: "",
          icon: "iconfont  icon-reset",
          size: "small",
          clickEvent: () => this.reset(),
          icon: "iconfont  icon-reset",
          text: this.$t("sys.button.reset") /* 重置*/
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          icon: "iconfont  icon-cancel",
          clickEvent: () => this.sendCode("0"),
          text: this.$t("sys.button.cancel") // 取消
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [],
      // 静态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "仓库编码",
          codeField: "WAREHOUSE_CODE",
          component: () => import("@/components/wms/commonInput"),
          span: 24,
          isRequire: true,
          type: "inputText",
          isMust: true,
          disabled: !this.isAdd(),
          dataToObject: {
            maxLength: 5
          }
        },
        {
          compKey: "compKey5",
          labelName: "仓库名称" /* 管理员角色*/,
          codeField: "WAREHOUSE_NAME",
          isRequire: true,
          span: 24,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey3",
          labelName: "仓库地址", // 管理员帐号
          span: 24,
          isRequire: true,
          codeField: "WAREHOUSE_ADDR",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey4",
          labelName: "联系人" /* 管理员密码*/,
          codeField: "LINK_MAN",
          isRequire: true,
          span: 24,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey6",
          labelName: "联系方式",
          codeField: "CANTACTS",
          span: 24,
          isRequire: true,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey7",
          labelName: "是否中心库", // 供应商名称
          codeField: "IS_CENTRE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 24,
          options: [
            {
              label: "是",
              value: "1"
            },
            {
              label: "否",
              value: "0"
            }
          ],
          isMust: true,
          isRequire: true
        },
        {
          compKey: "compKey8",
          labelName: "是否虚拟库", // 供应商名称
          codeField: "IS_VIRTUAL",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 24,
          options: [
            {
              label: "是",
              value: "1"
            },
            {
              label: "否",
              value: "0"
            }
          ],
          isMust: true,
          isRequire: true
        },
        {
          compKey: "compKey2",
          labelName: "状态", // 供应商名称
          codeField: "IS_ENABLE",
          isRequire: true,
          span: 24,
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "inputText",
          options: [
            {
              label: "启用",
              value: "1"
            },
            {
              label: "禁用",
              value: "0"
            }
          ],
          isMust: true
        }
      ],
      // 标题
      textMap: {
        edit: "修改仓库管理", // '修改供应商信息',
        add: "新增仓库管理" // '新增供应商信息'
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        WAREHOUSE_ID: "",
        WAREHOUSE_CODE: "",
        WAREHOUSE_NAME: "",
        WAREHOUSE_ADDR: "",
        LINK_MAN: "",
        CANTACTS: "",
        IS_CENTRE: "",
        IS_VIRTUAL: "",
        IS_ENABLE: "1"
      }
    };
  },
  methods: {
    // 保存
    save() {
      const that = this;
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        //保存表单
        this.saveForm();
      }
    }
  }
};
</script>
<style scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>
